package cn.com.visionsky.bocsz.bda.webservice.ws.client;

import cn.com.visionsky.bocsz.bda.webservice.handler.history_trans_query.HistoryTransQueryTest;
import cn.com.visionsky.bocsz.bda.webservice.ws.Application;
import cn.com.visionsky.bocsz.bda.webservice.ws.Reply;
import cn.com.visionsky.bocsz.bda.webservice.ws.WsControllerImplService;

import java.io.IOException;
import java.io.File;
import org.apache.commons.io.FileUtils;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by visionsky on 2017/3/20.
 */
public class Client {

	private static final Logger logger = LoggerFactory
            .getLogger(Client.class);
			
    public static Reply rout(Application application) throws IOException,URISyntaxException {
        File contextDir = new File(Reply.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile();
        logger.info("context dir: " + contextDir.getAbsolutePath());
        String urlStr = FileUtils.readFileToString(new File(contextDir, "config.txt"), "UTF-8");
		logger.info("url string:"+urlStr);
		URL url = null;
       
        try {
            url = new URL(urlStr);
        } catch (MalformedURLException ex) {
			logger.info("url create fail", ex);
        }
		
        return new WsControllerImplService(url).getWsControllerImplPort().route(application);
    }
}
